/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ro.model.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * @author L842359
 */
@Entity
@Table(name = "ocorrencia")
public class Ocorrencia implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
	@Column(name = "dtAbertura")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtAbertura;
	@Column(name = "dtConclusao")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtConclusao;
	@Column(name = "descricao")
	private String descricao;
	@Column(name = "prioridade")
	private Integer prioridade;
	@Column(name = "qtHoras")
	private Integer qtHoras;
	@JoinColumn(name = "grupo_id", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private Grupo grupoId;
	@JoinColumn(name = "objetoOcorrencia_id", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private ObjetoOcorrencia objetoOcorrenciaid;
	@JoinColumn(name = "usuario_id", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private Usuario usuarioId;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "ocorrenciaId")
	private List<Historico> historicoCollection;

	public Ocorrencia() {
	}

	public Ocorrencia(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getDtAbertura() {
		return dtAbertura;
	}

	public void setDtAbertura(Date dtAbertura) {
		this.dtAbertura = dtAbertura;
	}

	public Date getDtConclusao() {
		return dtConclusao;
	}

	public void setDtConclusao(Date dtConclusao) {
		this.dtConclusao = dtConclusao;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public Integer getPrioridade() {
		return prioridade;
	}

	public void setPrioridade(Integer prioridade) {
		this.prioridade = prioridade;
	}

	public Integer getQtHoras() {
		return qtHoras;
	}

	public void setQtHoras(Integer qtHoras) {
		this.qtHoras = qtHoras;
	}

	public Grupo getGrupoId() {
		return grupoId;
	}

	public void setGrupoId(Grupo grupoId) {
		this.grupoId = grupoId;
	}

	public ObjetoOcorrencia getObjetoOcorrenciaid() {
		return objetoOcorrenciaid;
	}

	public void setObjetoOcorrenciaid(ObjetoOcorrencia objetoOcorrenciaid) {
		this.objetoOcorrenciaid = objetoOcorrenciaid;
	}

	public Usuario getUsuarioId() {
		return usuarioId;
	}

	public void setUsuarioId(Usuario usuarioId) {
		this.usuarioId = usuarioId;
	}

	public List<Historico> getHistoricoCollection() {
		return historicoCollection;
	}

	public void setHistoricoCollection(List<Historico> historicoCollection) {
		this.historicoCollection = historicoCollection;
	}

	public Historico getLastHistorio(){
		if(historicoCollection != null && historicoCollection.size() > 0)
			return historicoCollection.get(historicoCollection.size()-1);
		return null;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Ocorrencia)) {
			return false;
		}
		Ocorrencia other = (Ocorrencia) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "br.com.ro.model.entity.Ocorrencia[ id=" + id + " ]";
	}

}
